import os
import shutil
import sys

try :
	dirname = sys.argv[1]
	if dirname[-1] != '/' :
		dirname + '/'
except :
	print sys.argv[0] + ' <directory_name>'
	print 'this script is used to prepend an id to bmp files in a directory'
	print 'more specifically, give us tile_ids for our tiles'

files = os.listdir(dirname)

next_file_id = 0

for file in files :

	if '.bmp' not in file :
		continue

	try :
		file_id, filename = file.split('_', 1)
		int(file_id)
	except :
		filename = file
	
	print file + ' to ' + str(next_file_id) + '_' + filename
	
	shutil.move(dirname + file, dirname + str(next_file_id) + '_' + filename)
	next_file_id += 1
